<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .inside {
        width: 100px;
        height: 100px;
        border: 1px solid;
        background-color: cyan;
        float: left;
        /* position: absolute; */
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="inside">1</div>
      <div class="inside">2</div>
      <div class="inside">3</div>
    </div>
    <script>
      var box = document.querySelectorAll(".inside");
      console.log(box);
      document.onkeydown = function (e) {
        var key = e.key;
        box.forEach(function (item, key) {
          // console.log(item, key);
          if (key == item.innerText) {
            item.style.background = "red";
          }
        });
      };
    </script>
  </body>
</html>
